
function EmailDocuments() {

    //Get the selected Items in the list
    var selectedItems = SP.ListOperation.Selection.getSelectedItems();
    var selectedItemIds = '';

    var count = CountDictionary(selectedItems);   // Gets the Count of the selected items

    if (count == 0) {
        return;
    }

    for (var i in selectedItems) {
        selectedItemIds += selectedItems[i].id + ',';     // Gets the ItemID for a selected item
    }
    //remove the trailing ,
    selectedItemIds = selectedItemIds.slice(0, -1);

    //Get the Id of the list
    var listId = SP.ListOperation.Selection.getSelectedList();

    //Use the SP API to get the page URL
    var pageUrl = SP.Utilities.Utility.getLayoutsPageUrl('EmailDocumentsAsAttachments/EmailDocuments.aspx');

    var options = {
        url: pageUrl + '?SelectedItems=' + selectedItemIds + '&SourceListId=' + listId,
        title: 'Email Documents',
        width: 640,
        height: 400
    }

    SP.UI.ModalDialog.showModalDialog(options);
}


function EmailDocumentsButtonEnabler() {
    //Specifies whether or now the Send Correspondance button should be enabled
    var selectedItems = SP.ListOperation.Selection.getSelectedItems();
    var count = CountDictionary(selectedItems);

    if (count < 1)
        return false;
    else
        return true;
}

